import 'package:flutter/material.dart';
import 'package:flutter06/pages/News.dart';
import 'package:flutter06/pages/other_page.dart';
import 'TabPage3.dart';
import 'TabPage2.dart';
import 'TabPage1.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _HomePageState();
  }
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
//定义底部导航Tab
  TabController _buttonNavigation;

  //定义底部导航项目
  final List<Tab> _bottomTabs = <Tab>[
    new Tab(
      text: 'Home',
      icon: new Icon(Icons.home),
    ),
    //icon和text的显示顺序已经内定，如需自定义，到child属性里面加吧
    new Tab(
      icon: new Icon(Icons.history),
      text: 'History',
    ),
    new Tab(
      icon: new Icon(Icons.book),
      text: 'Book',
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('MrLong'),
        backgroundColor: Colors.redAccent,
      ),
      //侧边栏填充内容
      drawer: new Drawer(
        child: new ListView(
          children: <Widget>[
            new UserAccountsDrawerHeader(
              accountName: new Text('Mrlong'),
              accountEmail: new Text('=='),
              currentAccountPicture: new GestureDetector(
                onTap: () => print('current user'),
                child: new CircleAvatar(
                  backgroundImage: new NetworkImage(
                      'https://upload.jianshu.io/users/upload_avatars/7700793/dbcf94ba-9e63-4fcf-aa77-361644dd5a87?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240'),
                ),
              ),
              otherAccountsPictures: <Widget>[
                new GestureDetector(
                  onTap: () => print('other user'),
                  child: new CircleAvatar(
                    backgroundImage: new NetworkImage(
                        'https://upload.jianshu.io/users/upload_avatars/10878817/240ab127-e41b-496b-80d6-fc6c0c99f291?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240'),
                  ),
                ),
              ],
              decoration: new BoxDecoration(
                  image: new DecorationImage(
                      image: new ExactAssetImage('images/lake.jpg'),
                      fit: BoxFit.fill)),
            ),
            new ListTile(
              title: new Text('第一个'),
              trailing: new Icon(Icons.arrow_upward),
              onTap: () {
                Navigator.of(context).pop();
                Navigator.of(context).push(new MaterialPageRoute(
                    builder: (BuildContext context) => new OtherPage('第一个')));
              },
            ),
            new ListTile(
              title: new Text('第二个'),
              trailing: new Icon(Icons.arrow_upward),
              onTap: () {
                Navigator.of(context).pop();
                Navigator.of(context).push(new MaterialPageRoute(
                    builder: (BuildContext context) => new OtherPage('第二个')));
              },
            ),
            new ListTile(
              title: new Text('第三个'),
              trailing: new Icon(Icons.arrow_upward),
              onTap: () {
                Navigator.of(context).pop();
                Navigator.of(context).pushNamed('/a');
              },
            ),
            new Divider(),
            new ListTile(
              title: new Text('关闭'),
              trailing: new Icon(Icons.cancel),
              onTap: () => Navigator.of(context).pop(),
            )
          ],
        ),
      ),
      body: new TabBarView(
        controller: _buttonNavigation, //配置控制器,
        children: <Widget>[
          new News(data: '参数值'),
          new TabPage2(),
          new TabPage3(),
        ],
      ),
      bottomNavigationBar: new Material(
        color: Colors.deepOrange,
        child: new TabBar(
          tabs: _bottomTabs,
          controller: _buttonNavigation,
          indicatorColor: Colors.white,
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    _buttonNavigation = new TabController(
        vsync: this, //动画效果的异步处理，默认格式，背下来即可
        length: 3 //需要控制的Tab页数量
        );
  }

  @override
  void dispose() {
    _buttonNavigation.dispose();
    super.dispose();
  }
}
